﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AppGisena.Models;
using Ext.Net;

namespace AppGisena.Presentacion
{
    public partial class Herramienta_Diagnostico : System.Web.UI.Page
    {

        private static BDGISENAEntities myconeccion=new BDGISENAEntities();
        TreePanel treePanelPrinc = new TreePanel();
        protected void Page_Load(object sender, EventArgs e)
        {




            Window win = new Window()
            {
                ID = "Window1",
                Title = "Ext.NET",
                Width = Unit.Pixel(1000),
                Height = Unit.Pixel(600),
                Modal = true,
                AutoRender = false,
                Collapsible = true,
                Maximizable = true,
                Hidden = false,
              
            };
        




           
            treePanelPrinc.ID = "trypanel";
            treePanelPrinc.Width = Unit.Pixel(800);
            treePanelPrinc.Height = Unit.Pixel(700);
           

            
            treePanelPrinc.Icon = Icon.BugMagnify;
            
            treePanelPrinc.Title = "HERRAMIENTA DE DIAGNOSTICO";
            treePanelPrinc.AutoScroll = true;

            this.PlaceHolder1.Controls.Add(treePanelPrinc);


           treePanelPrinc.Listeners.ItemClick.Handler = "#{DirectMethods}.Evaluar(record.data.text);";
           //treePanelPrinc.Listeners.CheckChange.Handler = "#{DirectMethods}.Evaluar(record.data.text);";

            Ext.Net.Node root = new Ext.Net.Node()
            {
                Text = "ASPECTOS HA EVALUAR"
            };
            root.Expanded = true;
            treePanelPrinc.Root.Add(root);

        

         foreach (Aspecto myaspecto in getlistAspecto())
         {
                 Ext.Net.Node composerNode = new Ext.Net.Node()
                 {
                     Text = myaspecto.Id_Aspecto+"-"+myaspecto.Nomb_Asp,
                     Icon =Icon.BulletKey
                    
                 };
                 root.Children.Add(composerNode);



                 foreach (Detalle_Aspecto myDetalleaspecto in getlistDetalleAsp(myaspecto.Id_Aspecto))
               {


                   Ext.Net.Node pieceNode = new Ext.Net.Node()
                   {
                       Text =myDetalleaspecto.Id_Det_Asp +"-"+ myDetalleaspecto.Nomb_Det_Asp,
                       Checked = false,
                         Icon =Icon.ChartPie,
                       Leaf = true
                   };
                   composerNode.Children.Add(pieceNode);
                     

               }
         }


        

        }



        [DirectMethod]
        public void Evaluar(String menj) {

            Ventana_Eval_HD.Title ="EVALUAR : "+ menj;


           
            Ventana_Eval_HD.Show();

            string[] Cod_Deta = menj.Split('-');

            Id_Det_Aspecto.Text = Cod_Deta[0];
            Det_Aspecto.Text = Cod_Deta[1];
                
               // Ventana_Eval_HD.Title;
        
           // X.Msg.Alert("",""+treePanelPrinc.GetCheckedNodes().).Show();
        
        }



        protected void Btn_Guardar_Asp_Diag_Click(object sender, DirectEventArgs e)
        {


            try
            {
                X.Msg.Alert("GISENA", "Hol registrar el diagnostico de la unidad productiva").Show();

                Ventana_Eval_HD.Close();
                
           

                Txt_Observ_Diag.Text = "";
                
            }
            catch (Exception ex)
            {

            }

        }



        public List<Aspecto> getlistAspecto()
        {
            return myconeccion.Aspecto.ToList();

        }

        public List<Detalle_Aspecto> getlistDetalleAsp(long idAspecto)
        {

            return myconeccion.Detalle_Aspecto.Where(s => s.Id_Aspecto == idAspecto).ToList();
        }

       

    }
}